﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.StopZero.CApStopZeroLocationOrOperationValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.StopZero.Resources;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.StopZero;

public sealed class CApStopZeroLocationOrOperationValidator(
  Func<ITxRoboticLocationOperation> getOppositeLocation) : CApStopZeroLocationValidator(getOppositeLocation)
{
  public Tuple<ITxRoboticLocationOperation, ITxRoboticLocationOperation> GetLocations(
    ITxRoboticOrderedCompoundOperation operation)
  {
    Tuple<ITxRoboticLocationOperation, ITxRoboticLocationOperation> tuple = this[(ITxObject) operation] as Tuple<ITxRoboticLocationOperation, ITxRoboticLocationOperation>;
    return new Tuple<ITxRoboticLocationOperation, ITxRoboticLocationOperation>(tuple.Item1, tuple.Item2);
  }

  protected override string GetNonCachedValidationError(ITxObject obj)
  {
    return !(obj is ITxRoboticOrderedCompoundOperation) ? base.GetNonCachedValidationError(obj) : (string) null;
  }

  protected override string GetCachedValidationError(ITxObject obj)
  {
    if (!(obj is ITxRoboticOrderedCompoundOperation compoundOperation))
      return base.GetCachedValidationError(obj);
    TxTypeFilter txTypeFilter = new TxTypeFilter(typeof (ITxRoboticLocationOperation));
    TxObjectList allDescendants = ((ITxObjectCollection) compoundOperation).GetAllDescendants((ITxTypeFilter) txTypeFilter);
    if (((Collection<ITxObject>) allDescendants).Count < 2)
      return StopZeroStringTable.NotEnoughLocations;
    ITxRoboticLocationOperation locationOperation1 = ((IEnumerable<ITxObject>) allDescendants).First<ITxObject>() as ITxRoboticLocationOperation;
    string cachedValidationError1 = base.GetCachedValidationError((ITxObject) locationOperation1);
    if (cachedValidationError1 != null)
      return cachedValidationError1;
    ITxRoboticLocationOperation locationOperation2 = ((IEnumerable<ITxObject>) allDescendants).Last<ITxObject>() as ITxRoboticLocationOperation;
    string cachedValidationError2 = base.GetCachedValidationError((ITxObject) locationOperation2);
    if (cachedValidationError2 != null)
      return cachedValidationError2;
    this[obj] = (object) new Tuple<ITxRoboticLocationOperation, ITxRoboticLocationOperation>(locationOperation1, locationOperation2);
    return (string) null;
  }
}
